//
//  PictireViewCell.m
//  XiangMuB
//
//  Created by 999999999999 on 16/8/18.
//  Copyright © 2016年 lanou3g. All rights reserved.
//

#import "PictireViewCell.h"
#import "PictureModel.h"
#import <UIImageView+WebCache.h>
#import "Content.h"
#import <DALabeledCircularProgressView.h>
#import "showpictureViewController.h"
@interface PictireViewCell ()
@end
@implementation PictireViewCell



-(void)awakeFromNib {
    //cell的背景图片
    UIImageView *bgView = [[UIImageView alloc]init];
    bgView.image = [UIImage imageNamed:@"mainCellBackground"];
    self.backgroundView = bgView;
    //给图片添加监听器
    self.img.userInteractionEnabled = YES;
    [self.img addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showPicture)]];
}
#pragma mark ---点击图片监听
-(void)showPicture{
//    NSLog(@"%s",__func__);
    showpictureViewController *showPic =[[showpictureViewController alloc]init];
    showPic.model = self.model;
    //显示根视图控制器
    [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:showPic animated:YES completion:nil];
}
-(void)setFrame:(CGRect)frame {
    frame.origin.x = 10;
    frame.size.width -= 2*frame.origin.x;
    frame.size.height -= 6;
    frame.origin.y += 10;
    [super setFrame:frame];
}
-(void)setModel:(PictureModel *)model {
    _model = model;
    self.tiitle.text = model.text;
    self.timeLable.text = model.passtime;
    [self.iconImage sd_setImageWithURL:[NSURL URLWithString:model.profile_image]];
    self.name.text = model.name;
    [self setupButtonTitle:self.dingLable count:model.ding placeHolder:@"顶"];
    [self setupButtonTitle:self.caiLable count:model.cai placeHolder:@"踩"];
    [self setupButtonTitle:self.zhuanfa count:model.repost placeHolder:@"转发"];
    [self setupButtonTitle:self.pinglun count:model.comment placeHolder:@"评论"];
    //添加图片
    [self.img sd_setImageWithURL:[NSURL URLWithString:model.image2]];
#pragma mark ----设置进度条
//    
//    [self.img sd_setImageWithURL:[NSURL URLWithString:model.image2] placeholderImage:nil options:0 progress:^(NSInteger receivedSize, NSInteger expectedSize) {
//        self.progressView.hidden = NO;
//        [self.progressView setProgress:1.0 *receivedSize / expectedSize animated:YES];
//    } completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
//        self.progressView.hidden = YES;
//    }];
#pragma mark ---如果不是gif图则隐藏显示gif的图片
    //gif图
    NSString *extension = model.image2.pathExtension;
    self.gifImg.hidden = ![extension.lowercaseString isEqualToString:@"gif"];
   
//    点击查看大图
    if (model.isBigPicture) {
        self.bigImg.hidden = NO;
//        self.img.contentMode = UIViewContentModeScaleAspectFit;//能显示大图的全部图片
        self.img.contentMode = UIViewContentModeScaleAspectFill;
    }else {
        self.bigImg.hidden = YES;
        self.img.contentMode = UIViewContentModeScaleToFill;
    }
    
    
    
    
}

#pragma mark ---设置底部按钮文字
-(void)setupButtonTitle:(UIButton *)button count:(NSInteger)count placeHolder:(NSString *)placeholder{
    NSString *title = nil;
    if (count == 0) {
        title =  placeholder;
    }else  if (count > 10000) {
        title = [NSString stringWithFormat:@"%.1f万",count/10000.0];
    }else {
        title = [NSString stringWithFormat:@"%zd",count];
    }
    [button setTitle:title forState:UIControlStateNormal];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}
@end
